package org.pan.domain.db;

import org.pan.domain.DomainObject;
import org.pan.domain.enums.CardStatusEnum;
import org.pan.domain.enums.CardTypeEnum;

import javax.persistence.*;
import java.util.Date;

/**
 * 卡片信息
 *
 * Created by panmingzhi on 2015/12/24.
 */
@Entity
public class PhysicalCard extends DomainObject{

    public enum Property{
        identifier,serialNumber,status,type,lastUpdateTime
    }

    @Column(name = "PhysicalId", unique = true, nullable = false)
    private String identifier;

    @Column(name = "SerialNumber", unique = true, nullable = false)
    private String serialNumber;

    @Column(name = "Status", nullable = false)
    private CardStatusEnum status = CardStatusEnum.UnAssigned;

    @Column(name = "Type", nullable = false)
    @Enumerated(EnumType.STRING)
    private CardTypeEnum type = CardTypeEnum.ReadOnly;

    @Column(name = "LastUpdateTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdateTime;

    @ManyToOne
    private CardUser cardUser;

    @PreUpdate
    public void prePersist(){
        this.lastUpdateTime = new Date();
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }

    public CardStatusEnum getStatus() {
        return status;
    }

    public void setStatus(CardStatusEnum status) {
        this.status = status;
    }

    public CardTypeEnum getType() {
        return type;
    }

    public void setType(CardTypeEnum type) {
        this.type = type;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public CardUser getCardUser() {
        return cardUser;
    }

    public void setCardUser(CardUser cardUser) {
        this.cardUser = cardUser;
    }
}
